// components/SuperHelper.js
import { useEffect } from 'react';

const SuperHelper = () => {
    useEffect(() => {
        // 只在客户端执行
        const s = document.createElement('script');
        s.src = "https://superhelper-online.bj.bcebos.com/jssdk/js/SuperHelper.iife.js";
        s.onload = () => initializeSuperHelper(); // 确保脚本加载完成后再调用初始化函数
        document.body.appendChild(s);

        return () => {
            // 清理操作，移除脚本
            document.body.removeChild(s);
        }
    }, []);

    const initializeSuperHelper = () => {
        const { login, Renderer } = window.SuperHelper;

        login({
            ak: '3f8ff596ae330f203457b6ac7e8174c3',
            sk: 'c50e7315b41ef14a1b32d67dd2dfa2a7',
            host: 'http://10.0.162.231:3000'
            // host: 'https://superhelper.bce.baidu.com'
        });

        const renderer = new Renderer({
            aiChatHost: 'https://superhelper.bce.baidu.com',
        });
        renderer.render();
    };

    return null; // 由于不需要渲染任何 JSX，返回 null
};

export default SuperHelper;
